package com.yanqu.road.server.cmd;

import com.yanqu.road.player.Player;
import com.yanqu.road.player.PlayerControl;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.A_PLAYER_OFFLINE,desc = "心跳检测用户下线,与强制踢玩家下线区分")
public class PlayerOfflineCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        long userId = packet.getPlayerId();
        Player player = PlayerControl.getOnlinePlayer(userId);
        if (player != null) {
            PlayerControl.removePlayerOnline(userId,player.getChannel(),false);
        }else {
            PlayerControl.removePlayerOnline(userId, null,false);
        }
    }
}
